import Taro, { Component } from '@tarojs/taro'
import { View, Text, Image } from '@tarojs/components'
import './yishengdingdanliebiao.css'
import { AtInput, AtGrid, AtList, AtListItem, AtTabs, AtTabsPane, AtButton ,AtPagination } from 'taro-ui'
import app from '../../../../main.js'

export default class Xishengdingdanliebiao extends Component {

  config = {
    navigationBarTitleText: '订单列表'
  }

  constructor() {
    super(...arguments)
    this.state = {
      value: '',
      current: 0,
      getArray:[],
      arr:['未完成','','','待审核','已完成','已退货'],
      num:0,
      id:'',
      total: 0,
      current:1
    }
  }

  get(){
    let me = this;   
    let data ={
        pageNum:me.state.num,
        condition:me.$router.params.id,
    }

    // app.get('web/PRLOrder/getOrderList',data,function(res){
    //     me.setState({
    //         getArray:res.data.data.rows
    //     })
    //     console.log(res)            
    // })
    app.post('web/PRLOrder/orderList',data,function(res){
        console.log(res)
        var list = res.data.data.rows;
        for(var i = 0; i < list.length; i++) {
            var item = list[i];
            item.patientId = !item.patientId ? '' : item.patientId;
        }
        me.setState({
            getArray:list,
            total:res.data.data.total
        })
        console.log(res)            
    })

  }

  componentWillMount() { 
    this.get();
  }

  handleChange(value) {
    this.setState({
      value,
      current: value
    })
  }

  handleClick(value) {
    this.setState({
      current: value
    })
  }

  clickList(id){
      console.log(id)
      let docid = this.$router.params.id
      app.navigateTo('../shuruhuanzhexinxi/shuruhuanzhexinxi?id='+id+'&docid='+docid)
  }

  onpageChange(type, cr){
    console.log(type);
    console.log(cr);
    let me = this;
    let nums = me.state.num
    let current = type.current
    // console.log(current)
    if(current - me.state.num == 2){
        nums = nums+1
        me.setState({
            num:nums,
            current:current
        },()=>{
            this.get();
            // console.log(me.state.num)
        })
    }else{
        nums = nums-1
        me.setState({
            num:nums,
            current:current
        },()=>{
            this.get();
            // console.log(me.state.num)
        })
    }
    
  }

  go(){
    let docid = this.$router.params.id
    app.navigateTo('../shuruhuanzhexinxi/shuruhuanzhexinxi?id='+0+'&docid='+docid)
  }

  render() {
    return (
      <View className='yishengdingdanliebiao'>
        <AtList>
            {
                this.state.getArray.map((item,index)=>{
                    return(
                        <AtListItem
                            onClick={this.clickList.bind(this,item.id)}
                            title={item.patientId+' '+item.hospital}
                            note={item.creatTime}
                            extraText={this.state.arr[index]}
                            arrow='right'
                        />
                    )
                })
            }    
 
        </AtList>

        <View className='pag'>
            <AtPagination 
            total={this.state.total} 
            pageSize={10}
            current={this.state.current}
            onPageChange={this.onpageChange.bind(this)}
            >
            </AtPagination>   
        </View>
        

        <View className='empty'></View>

        <AtButton className='AtBtn' type='primary' onClick={this.go.bind(this)}>新建</AtButton>

      </View>
    )

  }


}

